﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace PIT.Labs.ProjectRepository.Owl2DotNet.Xsd
{
    class XsdDataProperty : XsdEntityBase, IDataProperty
    {
        internal List<XsdClass> domain;
        internal List<XsdDataProperty> parents;
        internal List<XsdDataProperty> children;

        public XsdDataProperty(XsdOntology o, string uri, XElement description) : base(o, uri)
        {
            this.domain = new List<XsdClass>();
            this.parents = new List<XsdDataProperty>();
            o.Insert(this);
        }

        public XsdDataProperty(XsdOntology o, string uri, XElement item, XsdDataProperty parent) : base(o, uri)
        {
            this.domain = new List<XsdClass>();
            this.parents = new List<XsdDataProperty>{parent};
            o.Insert(this);          
        }

        public IDataProperty SubProperties
        {
            get
            {
                if (children == null)
                {
                    children = new List<XsdDataProperty>();
                    foreach (var dp in ontology.dataProperties)
                    {
                        if (dp.Value.parents.Contains(this))
                        {
                            children.Add(dp.Value);
                        }
                    }
                }
                return children.FirstOrDefault();
            }
        }

        public IDataProperty SuperProperties
        {
            get { return this.parents.FirstOrDefault(); }
        }

        public IEnumerable<IClass> Domain
        {
            get { return domain.Select(x => (IClass)x); }
        }

        public IEnumerable<IDataType> Range
        {
            get { throw new NotImplementedException(); }
        }

        public PropertyCharacteristics Characteristics
        {
            get { throw new NotImplementedException(); }
        }
    }
}
